package com.nb.dao;

import com.nb.domain.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 用户数据层接口
 * Created by fly on 2017/11/12.
 */
@Mapper
@Repository
public interface UserDao {

    /**
     * 根据用户主键获取用户信息
     * @param userId
     * @return
     * @throws Exception
     */
    @Results({
            @Result(property = "userId", column = "u_id"),
            @Result(property = "userName", column = "user_name"),
            @Result(property = "passWord", column = "password"),
            @Result(property = "realName", column = "real_name")
    })
    @Select(value = "select * from user where u_id = #{userId}")
    User findUserById(@Param("userId") int userId) throws Exception;

    /**
     * 查询用户列表
     * @return
     * @throws Exception
     */
    @Results({
            @Result(property = "userId", column = "u_id"),
            @Result(property = "userName", column = "user_name"),
            @Result(property = "passWord", column = "password"),
            @Result(property = "realName", column = "real_name")
    })
    @Select(value = "select * from user")
    List<User> queryUserList() throws Exception;
}
